<template>
	<view class="mainpadding beijingse">
		<view class="titletext margin_top">上传身份证</view>
		<view class="ffffff mainpadding radius margin_top" @click="uploadImg(1)">
			<view class="shenfz">
				<image v-if="!fr_zimage_text" src="../../static/image/system/sfzzm.png" mode=""></image>
				<image v-if="fr_zimage_text" :src="fr_zimage_text" mode=""></image>
			</view>
			<view class="huisetext1 textcenter margin_top">点击上传身份证人像面</view>
		</view>
		<view class="ffffff mainpadding radius margin_top" @click="uploadImg(2)">
			<view class="shenfz">
				<image v-if="!fr_fimage_text" src="@/static/image/system/sfzfm.png" mode=""></image>
				<image v-if="fr_fimage_text" :src="fr_fimage_text" mode=""></image>
			</view>
			<view class="huisetext1 textcenter margin_top">点击上传身份证国徽面</view>
		</view>
		<view class="bigbtn margin_top6" @click="submit">确认</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				fr_zimage: "", //法人头像面
				fr_zimage_text: "", //法人头像面
				fr_fimage: "", //法人头像面
				fr_fimage_text: "", //法人国徽面
			}
		},
		methods: {
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			// 认证
			submit() {
				let _this = this
				if (_this.fr_zimage == "") {
					httpRequest.toast("请上传身份证头像面")
					return
				}
				if (_this.fr_fimage == "") {
					httpRequest.toast("请上传身份证国徽面")
					return
				}
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				httpRequest.request('/api/user/smrzApply', 'GET', {
					// 传参
					idcard_zimage: _this.fr_zimage,
					idcard_fimage: _this.fr_fimage,
				}, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}else{
						httpRequest.toast(res.msg)
					}
				}).catch(err => {
					uni.hideLoading()
					httpRequest.toast(err.message);
				})

			},
			uploadImg(upimg) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upimg)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i], upimg)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, upimg) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					if (upimg == 1) {
						this.fr_zimage = res.url
						this.fr_zimage_text = image_item
					} else if (upimg == 2) {
						this.fr_fimage = res.url
						this.fr_fimage_text = image_item
					}
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.kuand {
		width: 200rpx;
	}
	.textarea {
		padding: 20rpx;
		background: #F5F5F5;
		width: 66%;
		border-radius: 10rpx;
	}

	.shenfz {
		width: 407rpx;
		height: 197rpx;
		margin: auto;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>